import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../controllers/register_step_one_controller.dart';
import '../../../../utils/screenAdapter.dart';
import '../../../../common/widget/logo.dart';
import '../../../../common/widget/passTextField.dart';
import '../../../../common/widget/codeButton.dart';

class RegisterStepOneView extends GetView<RegisterStepOneController> {
  const RegisterStepOneView({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('手机号快速注册'),
        // centerTitle: true,
      ),
      body: ListView(
        padding: EdgeInsets.fromLTRB(
          ScreenAdapter.width(30),
          ScreenAdapter.height(100),
          ScreenAdapter.width(30),
          ScreenAdapter.height(30),
        ),
        children: [
          Logo(),
          SizedBox(height: ScreenAdapter.height(160)),
          PassTextField(
            hasBorder: true,
            hintText: "请输入手机号码",
            controller: controller.textEditingController,
            onChanged: (value) {
              print("手机号码: $value");
            },
          ),
          SizedBox(height: ScreenAdapter.height(170)),
          CodeButton(
            textContent: "下一步",
            onPressed: () async {
              // 校验手机号格式
              String phone = controller.textEditingController.text;
              if (phone.length == 11 && GetUtils.isPhoneNumber(phone)) {
                // 校验手机号格式
               bool success = await controller.sendCode(phone);
                if(success){
                  Get.toNamed("/register-step-two", arguments: {"tel" : phone});
                } 
              } else {
                Get.snackbar("提示", "手机号格式不正确");
              }
            },
          ),
          SizedBox(height: ScreenAdapter.height(40)),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text("遇到问题？您可以", style: TextStyle(color: Colors.black54)),
              Text('获取帮助', style: TextStyle(color: Colors.blue)),
            ],
          ),
        ],
      ),
    );
  }
}
